$(document).ready(function(){

    });

// Statements
function showStatements(){
    var url = $("#url4Statements").val();
    $.ajax ({
        type: "GET",
        url: url,
        success: function (html)
        {
            $('#DAH').html(html);
            $(".chzn-select").chosen();
            $(".datepicker").datepicker({
                dateFormat: 'yy-mm-dd'
            });
            $('.tipw').tipsy();
            $('#searchStatement').delegate('','click', function() {
                statementDetails();
            });
            $('#resetStatement').delegate('','click', function() {
                resetStatementForm();
            });
        }
    });
}

function resetStatementForm(){
    $('#statement_line_id').val('').trigger('liszt:updated');
    $('#statement_customer_id').val('').trigger('liszt:updated');
    $('#statement_fromDate').val('');
    $('#statement_toDate').val('');
}

function statementDetails(){
    var data = $("#form").serialize();
    var url  = $("#url4Statements").val();
    $.ajax ({
        type: "POST",
        url: url,
        data :data,
        success: function (html)
        {
            if (html.indexOf("form") >= 0){
                $('#DAH').html(html);
                $(".chzn-select").chosen();
                $(".datepicker").datepicker({
                    dateFormat: 'yy-mm-dd'
                });
                $('.tipw').tipsy();
                $('#searchStatement').delegate('','click', function() {
                    statementDetails();
                });
                $('#resetStatement').delegate('','click', function() {
                    resetStatementForm();
                });
            }
            else
                $('.ressultDiv').html(html);
        }
    });
}

// Due Sheets
function showDueSheets(){
 var url = $("#url4DueSheets").val();
    $.ajax ({
        type: "GET",
        url: url,
        success: function (html)
        {
            $('#DAH').html(html);
        }
    });   
}